local skel = fk.CreateSkill {
  name = "role_exmode_mingtu__lb_yi",
}

Fk:loadTranslationTable {
  ["role_exmode_mingtu__lb_yi"] = "忆",
  [":role_exmode_mingtu__lb_yi"] = "出牌阶段限一次，你可以将两张牌当上一张被使用的基本牌或普通锦囊牌使用。",
  ["#role_exmode_mingtu__lb_yi"] = "忆：你可以将两张牌当 %arg 使用",
  ["@role_exmode_mingtu__lb_yi"] = "忆",
}

skel:addEffect("viewas", {
  pattern = ".",
  prompt = function (self, player, selected_cards, selected)
    return "#role_exmode_mingtu__lb_yi:::"..player:getMark("@role_exmode_mingtu__lb_yi")
  end,
  handly_pile = true,
  filter_pattern = {
    min_num = 2,
    max_num = 2,
    pattern = ".",
  },
  view_as = function (self, player, cards)
    if #cards ~= 2 then return nil end
    local c = Fk:cloneCard(player:getMark("@role_exmode_mingtu__lb_yi"))
    c.skillName = skel.name
    c:addSubcards(cards)
    return c
  end,
  enabled_at_play = function(self, player)
    if player:usedSkillTimes(skel.name, Player.HistoryPhase) == 0 and #player:getCardIds("he") > 1 
    and player.phase == Player.Play
    and player:getMark("@role_exmode_mingtu__lb_yi") ~= 0 then
      local card = Fk:cloneCard(player:getMark("@role_exmode_mingtu__lb_yi"))
      if Fk.currentResponsePattern == nil then
        return player:canUse(card)
      else
        return Exppattern:Parse(Fk.currentResponsePattern):match(card)
      end
    end
  end,
  enabled_at_response = function (self, player, response)
    if not response and player:usedSkillTimes(skel.name, Player.HistoryPhase) == 0 and player.phase == Player.Play
    and #player:getCardIds("he") > 1 and player:getMark("@role_exmode_mingtu__lb_yi") ~= 0 then
      local card = Fk:cloneCard(player:getMark("@role_exmode_mingtu__lb_yi"))
      if Fk.currentResponsePattern == nil then
        return player:canUse(card)
      else
        return Exppattern:Parse(Fk.currentResponsePattern):match(card)
      end
    end
  end,
})

skel:addEffect(fk.CardUsing, {
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(skel.name, true) and (data.card.type == Card.TypeBasic or data.card:isCommonTrick())
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player, "@role_exmode_mingtu__lb_yi", data.card.name)
  end,
})

skel:addAcquireEffect(function (self, player, is_start)
  player.room.logic:getEventsByRule(GameEvent.UseCard, 1, function (e)
    local card = e.data.card
    if card.type == Card.TypeBasic or card:isCommonTrick() then
      player.room:setPlayerMark(player, "@role_exmode_mingtu__lb_yi", card.name)
      return true
    end
  end, 0)
end)

skel:addLoseEffect(function (self, player, is_death)
  player.room:setPlayerMark(player, "@role_exmode_mingtu__lb_yi", 0)
end)

return skel